home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Communication / NewsBase / Source / IBaseControl.m < prev    next >
Text File  |  1993-01-12  |  10KB  |  330 lines

  1. /*$Copyright:
  2.  * Copyright (C) 1992.5.22. Recruit Co.,Ltd. 
  3.  * Institute for Supercomputing Research
  4.  * All rights reserved.
  5.  * NewsBase  by ISR, Kazuto MIYAI, Gary ARAKAKI, Katsunori SUZUKI, Kok-meng Lue
  6.  *
  7.  * You may freely copy, distribute and reuse the code in this program under 
  8.  * following conditions.
  9.  * - to include this notice in the source code, if it is to be distributed 
  10.  *   with source code.
  11.  * - to add the file named "COPYING" within the code, which shall include 
  12.  *   GNU GENERAL PUBLIC LICENSE(*).
  13.  * - to display an acknowledgement in binary code as follows: "This product
  14.  *   includes software developed by Recruit Co.,Ltd., ISR."
  15.  * - to display a notice which shall state that the users may freely copy,
  16.  *   distribute and reuse the code in this program under GNU GENERAL PUBLIC
  17.  *   LICENSE(*)
  18.  * - to indicate the way to access the copy of GNU GENERAL PUBLIC LICENSE(*)
  19.  *
  20.  *   (*)GNU GENERAL PUBLIC LICENSE is stored in the file named COPYING
  21.  * 
  22.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  23.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  24.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  25. $*/
  26. /* IBaseControl.m */
  27.  
  28. #import <appkit/appkit.h>
  29. #import <mach/mach_init.h>
  30. #import <defaults/defaults.h>
  31. #import <libc.h>
  32. #import "IBaseControl.h"
  33. #import "INewsBase.h"
  34. #import "IIOmodule.h"
  35. #import "TransparentWindow.h"
  36. #import "IDocTransparentWindow.h"
  37. #import "data_types.h"
  38. #import "errdebug.h"
  39. #import "IReceiveSpeaker.h"
  40. #import "IReceiveListener.h"
  41. #import "Localization.h"
  42. #import "IHelp.h"
  43. #import "InfoPanel.h"
  44.  
  45. #define LoStr(key)      doLocalString(NULL,key,NULL)
  46.  
  47. struct windowDef {
  48.     @defs(Window)
  49. };
  50.  
  51. @implementation IBaseControl
  52.  
  53. - appWillInit:sender
  54. {
  55.     [NXApp setAppSpeaker:[[IReceiveSpeaker alloc] init]];
  56.     [NXApp setAppListener:[[IReceiveListener alloc] init]];
  57.     return(self);
  58. }
  59.  
  60. - appDidInit:sender
  61. {
  62.     iHelpPanel = nil;
  63.     iInfoPanel = nil;
  64.     
  65.     [oMenuTitle setTitle:"NewsBase3.0"];
  66.     if ((nntpBase = [[INewsBase alloc] init]) == nil) {
  67.         return(nil);
  68.     }
  69.     [nntpBase show:self];
  70.     return(self);
  71. }
  72.  
  73. - appWillTerminate:sender
  74. {
  75.     int n;
  76.     Window *window;
  77.     List *windowList;
  78.     Class isA;
  79.  
  80.     [nntpBase terminateProc];
  81.     
  82.     DBG(1, [self debug];);
  83.     windowList = [NXApp windowList];
  84.     for (n = 0; window = [windowList objectAt:n]; ++n) {
  85.         if (NXZoneFromPtr(window) == 0) {
  86.             DBG(1, fprintf(stderr, "NXZoneFromPtr(window = %#x) = %#x\n",
  87.                 (unsigned int)window, (unsigned int)NXZoneFromPtr(window)););
  88.             [windowList removeObject:window];
  89.             --n;
  90.             continue;
  91.         }
  92.         if ((isA = ((struct windowDef *)window)->isa) != (Class)[Window class]
  93.             && isA != (Class)[Panel class] && isA != (Class)[Menu class] &&
  94.             isA != (Class)[PopUpList class]) {
  95.             DBG(1, fprintf(stderr, "(window = %#x)->isa = %#x\n",
  96.                 (unsigned int)window, (unsigned int)((struct windowDef *)window)->isa););
  97.             [windowList removeObject:window];
  98.             --n;
  99.         }
  100.     }
  101.     // remove all temporary files
  102.     return(self);
  103. }
  104.  
  105. - openViewControlPanel:sender
  106. {
  107.     if ([nntpBase respondsTo:@selector(openViewControlPanel:)]) {
  108.     [nntpBase openViewControlPanel:self];
  109.     return self;
  110.     } else {
  111.     return nil;
  112.     }
  113. }
  114.  
  115. - browserDidBecomeKey:sender
  116. {
  117. //    [oBrowserControlMenuCell setEnabled:YES];
  118.     if ([sender class] == [INewsBase class]) {
  119.     [oUnscribeNewsgroupMenuCell setEnabled:YES];
  120.     [oUnscribeNewsgroupMenuCell setTarget:sender];
  121.     [oUnscribeNewsgroupMenuCell setAction:@selector(unSubscribeGroup:)];
  122.     
  123.     [oShowAllArticleMenuCell setEnabled:YES];
  124.     [oShowAllArticleMenuCell setTarget:sender];
  125.     [oShowAllArticleMenuCell setAction:@selector(setReadFlagToAll:)];
  126.     
  127.     [oSortBySubjectMenuCell setEnabled:YES];
  128.     [oSortBySubjectMenuCell setTarget:sender];
  129.     [oSortBySubjectMenuCell setAction:@selector(toggleArticleBrowser:)];
  130.     
  131.     [oSortByKeywordMenuCell setEnabled:YES];
  132.     [oSortByKeywordMenuCell setTarget:sender];
  133.     [oSortByKeywordMenuCell setAction:@selector(toggleArticleBrowser:)];
  134.     
  135.     [oArticleBrowserMenuCell setEnabled:YES];
  136.     [oArticleBrowserMenuCell setTarget:sender];
  137.     [oArticleBrowserMenuCell setAction:@selector(toggleArticleBrowser:)];
  138.     
  139.     [oArticleListMenuCell setEnabled:YES];
  140.     [oArticleListMenuCell setTarget:sender];
  141.     [oArticleListMenuCell setAction:@selector(toggleArticleBrowser:)];
  142.     
  143.     [oNewsgroupBrowserMenuCell setEnabled:YES];
  144.         [oNewsgroupBrowserMenuCell setTarget:sender];
  145.     [oNewsgroupBrowserMenuCell
  146.                  setAction:@selector(toggleNewsGroupBrowser:)];
  147.                  
  148.     [oNewsgroupListMenuCell setEnabled:YES];
  149.         [oNewsgroupListMenuCell setTarget:sender];
  150.     [oNewsgroupListMenuCell setAction:@selector(toggleNewsGroupBrowser:)];
  151.  
  152.     [oMarkAllArticleMenuCell setEnabled:YES];
  153.         [oMarkAllArticleMenuCell setTarget:sender];
  154.     [oMarkAllArticleMenuCell setAction:@selector(markAllArticleAsRead:)];
  155.  
  156.     [oNewArticlesMenuCell setEnabled:YES];
  157.         [oNewArticlesMenuCell setTarget:sender];
  158.     [oNewArticlesMenuCell setAction:@selector(getNewArticles:)];
  159.     }
  160.     return(self);
  161. }
  162.  
  163. - browserDidResignKey:sender
  164. {
  165.     [oUnscribeNewsgroupMenuCell setEnabled:NO];
  166.     [oShowAllArticleMenuCell setEnabled:NO];
  167.     [oSortBySubjectMenuCell setEnabled:NO];
  168.     [oSortByKeywordMenuCell setEnabled:NO];
  169.     [oArticleBrowserMenuCell setEnabled:NO];
  170.     [oArticleListMenuCell setEnabled:NO];
  171.     [oNewsgroupBrowserMenuCell setEnabled:NO];
  172.     [oNewsgroupListMenuCell setEnabled:NO];
  173.     [oMarkAllArticleMenuCell setEnabled:NO];
  174.     [oNewArticlesMenuCell setEnabled:NO];
  175. //    [oBrowserControlMenuCell setEnabled:NO];
  176.     return(self);
  177. }
  178.  
  179. -(int)receiveArticle:(char *)article length:(int)length
  180. {
  181. //    fprintf(stderr, "%80s\n", article);
  182.     [nntpBase postArticle:article length:length];
  183.     return(0);
  184. }
  185.  
  186. - (int)sendArticleWithMessageID:(const char *)messageID
  187. {
  188.     [nntpBase sendArticle:messageID];
  189.     return(0);
  190. }
  191.  
  192. - (int)makeMimeIconWindowAtpointX:(int)x pointY:(int)y 
  193.             offsetX:(int)offx offsetY:(int)offy
  194.             sourceWindow:(int)wnum
  195. {
  196.     id        iconWindow;
  197.     id        image;
  198.     NXPoint    originPoint;
  199.     NXPoint    offset;
  200.  
  201.     originPoint.x = x;
  202.     originPoint.y = y;
  203.     image = [NXImage findImageNamed:MIMEDOCICON];
  204.     iconWindow = [[IDocTransparentWindow
  205.             allocFromZone:[self zone]] 
  206.             initForImage:image
  207.             at:&originPoint
  208.             forView:NULL];
  209.     [iconWindow setSourceWindowNum:wnum];
  210.     offset.x = offx;
  211.     offset.y = offy;
  212.     
  213.     [NXApp activateSelf:YES];
  214.     [iconWindow dragFromMouseDown:&originPoint mouseOffset:&offset];
  215.     return (0);
  216. }
  217.  
  218. - setOMainMenu:mainMenu
  219. {
  220.     oMainMenu = mainMenu;
  221.     return(self);
  222. }
  223.  
  224. - openHelpPanel:sender
  225. {
  226.     if (iHelpPanel == nil) {
  227.     iHelpPanel = [[IHelp allocFromZone:[self zone]] init];
  228.     }
  229.     [iHelpPanel openHelpPanel:sender];
  230.     return self;
  231. }
  232.  
  233. - openInfoPanel:sender
  234. {
  235.     if (iInfoPanel == nil) {
  236.     iInfoPanel = [[InfoPanel allocFromZone:[self zone]] init];
  237.     }
  238.     [iInfoPanel openInfoPanel:sender];
  239.     return self;
  240. }
  241.  
  242. #ifdef DEBUG
  243.  
  244. - (void)debug
  245. {
  246.     DBG(1, fprintf(stderr, "NXMallocCheck() = %d\n", NXMallocCheck()););
  247.     DBG(1, {
  248.         int *screenWindowList;
  249.         int screenWindowListCount;
  250.         List *windowList;
  251.         int n;
  252.         Window *window;
  253.         int windowNum;
  254.         NXRect rect;
  255.         BOOL isVisible;
  256.         NXZone *zone;
  257.         char response[256];
  258.         Class isA;
  259.  
  260.         fprintf(stderr, 
  261.       "NXDefaultMallocZone() = %x\n", (unsigned int)NXDefaultMallocZone());
  262.         fprintf(stderr, "Windows for this Application\n");
  263.         [NXApp getWindowNumbers:&screenWindowList 
  264.                 count:&screenWindowListCount];
  265.         fprintf(stderr, 
  266.       "screen window count = %d\n", (int)screenWindowListCount);
  267.         for (n = 0; n < screenWindowListCount; ++n) {
  268.             fprintf(stderr, "%d ", (int)screenWindowList[n]);
  269.         }
  270.         fprintf(stderr, "\n");
  271.         windowList = [NXApp windowList];
  272.         fprintf(stderr, "window count = %d\n", (int)[windowList count]);
  273.         for (n = 0; window = [windowList objectAt:n]; ++n) {
  274.             if (NXZoneFromPtr(window) == 0) {
  275.                 fprintf(stderr, "NXZoneFromPtr(window = %#x) = %#x\n",
  276.                     (unsigned int)window, (unsigned int)NXZoneFromPtr(window));
  277.                 continue;
  278.             }
  279.             if ((isA = ((struct windowDef *)window)->isa) != [Window class] &&
  280.                 isA != [Panel class] && isA != [Menu class] &&
  281.                 isA != [PopUpList class]) {
  282.                 fprintf(stderr, "(window = %#x)->isa = %#x\n",
  283.                     (unsigned int)window, 
  284.             (unsigned int)((struct windowDef *)window)->isa);
  285.                 continue;
  286.             }
  287.             windowNum = [window windowNum];
  288.             [window getFrame:&rect];
  289.             isVisible = [window isVisible];
  290.             zone = [window zone];
  291.             fprintf(stderr, "window = %x, window number = %2d, zone = %x, "
  292.                 "width = %7.0f, height = %7.0f, "
  293.                 "is visible %s\n",
  294.                 (unsigned int)window, (int)windowNum, 
  295.         (unsigned int)zone, 
  296.         rect.size.width, rect.size.height,
  297.                 isVisible == YES ? "YES" : "NO");
  298.         }
  299.         for (n = 0; window = [windowList objectAt:n]; ++n) {
  300.             if (NXZoneFromPtr(window) == 0) {
  301.                 fprintf(stderr, "NXZoneFromPtr(window = %#x) = %#x\n",
  302.                     (unsigned int)window, (unsigned int)NXZoneFromPtr(window));
  303.                 continue;
  304.             }
  305.             if ((isA = ((struct windowDef *)window)->isa) != [Window class] &&
  306.                 isA != [Panel class] && isA != [Menu class] &&
  307.                 isA != [PopUpList class]) {
  308.                 fprintf(stderr, "(window = %#x)->isa = %#x\n",
  309.                     (unsigned int)window, 
  310.             (unsigned int)((struct windowDef *)window)->isa);
  311.                 continue;
  312.             }
  313.             windowNum = [window windowNum];
  314.             isVisible = [window isVisible];
  315.             if (windowNum > 0 && isVisible == NO) {
  316.                 fprintf(stderr, "orderFront: sent to window number %d"
  317.                     " return to continue > ", (int)windowNum);
  318.                 [window orderFront:self];
  319.                 NXPing();
  320.         fgets(response, sizeof(response), stdin);
  321.                 [window orderOut:self];
  322.             }
  323.         }
  324.     });
  325. }
  326.  
  327. #endif
  328.  
  329. @end
  330.